//
//  ViewController.m
//  ChangeLabelColor_Code
//
//  Created by niit on 16/1/29.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)addButtonWithTile:(NSString *)tile andFrame:(CGRect)fram andTag:(int)tag// andColor:(UIColor *)color
{
    // 创建按钮
    UIButton *btn = [[UIButton alloc] initWithFrame:fram];
    
    // 设置按钮文字
    [btn setTitle:tile forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    
    btn.titleLabel.font = [UIFont systemFontOfSize:15];
    btn.tag = tag;
    
    // 添加事件
    [btn addTarget:self action:@selector(btnPressed:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:btn];
    
    
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    // 创建Label
    self.label = [[UILabel alloc] init];
    self.label.frame = CGRectMake(49, 136, 306, 21);
    self.label.text = @"Label";
    self.label.textColor = [UIColor blackColor];
    [self.view addSubview:self.label];
    
    // 创建4个按钮
    [self addButtonWithTile:@"简单提示框" andFrame:CGRectMake(8,35,124,32) andTag:1];
    [self addButtonWithTile:@"多按钮" andFrame:CGRectMake(0,67,124,32) andTag:2];
    [self addButtonWithTile:@"带输入框" andFrame:CGRectMake(8,101,124,32) andTag:3];
    [self addButtonWithTile:@"操作表" andFrame:CGRectMake(0,165,124,32) andTag:4];

}

- (void)btnPressed:(UIButton *)sender
{
    if (sender.tag == 1)
    {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"弹出框标题" message:@"弹出框信息" preferredStyle:UIAlertControllerStyleAlert];
        
        [self presentViewController:alert animated:YES completion:nil];
        
        UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
        
        [alert addAction:sureAction];
    }
    if (sender.tag == 2)
    {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"弹出窗口2" message:@"中饭吃了没?" preferredStyle:UIAlertControllerStyleAlert];
        
        [self presentViewController:alert animated:YES completion:nil];
        
        UIAlertAction *eatAction = [UIAlertAction actionWithTitle:@"吃了" style:UIAlertActionStyleCancel handler:nil];
        UIAlertAction *eatingAction = [UIAlertAction actionWithTitle:@"正在吃" style:UIAlertActionStyleDefault handler:nil];
        UIAlertAction *noAction = [UIAlertAction actionWithTitle:@"还没吃" style:UIAlertActionStyleDefault handler:nil];
        
        [alert addAction:eatAction];
        [alert addAction:eatingAction];
        [alert addAction:noAction];
    }
    if (sender.tag == 3)
    {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"登入" message:@"请输入用户名密码" preferredStyle:UIAlertControllerStyleAlert];
        
        
        [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
            textField.placeholder = @"Login";
        }];
        [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
            textField.placeholder = @"Password";
            textField.secureTextEntry = YES;
        }];
        
        [self presentViewController:alert animated:YES completion:nil];
        
        UIAlertAction *CancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
        UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
        
        [alert addAction:CancelAction];
        [alert addAction:defaultAction];
//        if ([defaultAction.title isEqualToString:@"确定"])
//        {
//            self.label.text =
//        }
    }
    if (sender.tag == 4)
    {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"小明:一起去吃饭吧?" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
        
        [self presentViewController:alert animated:YES completion:nil];
        
        UIAlertAction *eatAction = [UIAlertAction actionWithTitle:@"我吃过了,你去吧." style:UIAlertActionStyleCancel handler:nil];
        UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"好的,一起去" style:UIAlertActionStyleDestructive handler:nil];
        UIAlertAction *eatingAction = [UIAlertAction actionWithTitle:@"一起去吃KFC" style:UIAlertActionStyleDefault handler:nil];
        UIAlertAction *noAction = [UIAlertAction actionWithTitle:@"一起去吃MC" style:UIAlertActionStyleDefault handler:nil];
        
        [alert addAction:eatAction];
        [alert addAction:okAction];
        [alert addAction:eatingAction];
        [alert addAction:noAction];
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
